package SpaceIT.pages;
import java.util.ArrayList;

import model.dao.SanPhamDAO;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import view.util.util;

public class ChiTietLapTop 
{
	@Inject
	private Request request;
	
	@Property
	private util viewHelper = new util();
	
	@Property
	private int i;
	
	@Property
	private ArrayList<String> ttChiTiet;
	
	@Property
	private ArrayList<String> spCungDongSanPham;
	
	public void onActivate()
	{
		String s = request.getParameter("MaSP");
		if(s == null)
			return;
		setTTChiTiet(s);
		getSpCungDongSanPham(this.getDongSanPham());
	}
	
	public ArrayList<String> getTTChiTiet(){
//	{
		return ttChiTiet;
	}
		
	public void setTTChiTiet(String MaSP){
//	{
		ttChiTiet = SanPhamDAO.ChiTietLapTop(MaSP);
	}

	private void getSpCungDongSanPham(String DongSP) {
//	{
		ArrayList<ArrayList<String>> spcl = SanPhamDAO.SanPhamCungDongSanPham(DongSP);
		spCungDongSanPham = new ArrayList<String>();
		
		for(int i = 0 ; i < spcl.size() ; i = i + 3)
		{
			String s = "";
			String url = "ChiTietLapTop?MaSP=";
			
			for(int j = 0 ; j < 3 && j + i < spcl.size() ; j++ )
			{
				s += "<div class='products_list_content_item'>";
				s += "	<div class='products_list_content_item_pic'>";
				s += "		<a href='" + url + spcl.get(j + i).get(0) + "' title='" + spcl.get(j + i).get(1) +"'>";
				s += "			<img src='" + spcl.get(j + i).get(7) + "' alt='" + spcl.get(j + i).get(1) +" width='120px' height='120px'/>";
				s += "		</a>";
				s += "		<p><br/>" + spcl.get(j + i).get(2) + " VNĐ</p>";
				s += "		<div class='luotxem'> Lượt xem: " + spcl.get(j + i).get(6) + "</div>";
				s += "	</div>";
				s += "	<div class='products_list_content_item_main'>";
				s += "		<div class='products_list_content_item_name'>";
				s += "			<a href='" + url + spcl.get(j + i).get(0) + "' title='" + spcl.get(j + i).get(1) +"'>";
				s +=  				spcl.get(j + i).get(1);
				s += "			</a>";
				s += "		</div>";
				s += "		<div class='products_list_content_item_des'>";
				s += "			<span style='font-size: small; font-family: arial,helvetica,sans-serif;'>";
				s += 				spcl.get(j + i).get(3);	
				s += "			</span>"; 
				s += "			<br/>";
				s += "		</div>";
				s += "		<div class='products_list_content_item_warr'>";
				s += "			<span class='warr_padd' style='padding-left: 20px;'>Bảo hành: " + spcl.get(j + i).get(4) + " Tháng</span>";
				s += "			<span class='warr_padd'> Kho: " + spcl.get(j + i).get(5) + "</span>";
				s += String.format("<input type='image' style='float: right;' src='layout/images/GiaoDien/dathang.gif' MaSP='%s' TenSP='%s' GiaBan='%s' linkHinh='%s' class='btnMua' />",spcl.get(j + i).get(0) , spcl.get(j + i).get(1) , spcl.get(j + i).get(2),spcl.get(j + i).get(7));
				s += "			<div style='clear: both; margin-bottom: 3px;'></div>";
				s += "		</div>";
				s += "	</div>";
				s += "	<div class='clr products_list_content_bot'></div>";
				s += "</div>";
			}
			spCungDongSanPham.add(s);
		}
	}
	
	public String getMaSP(){
//	{
		return ttChiTiet.get(0);
	}
	public String getTenSP(){
//	{
		return ttChiTiet.get(1);
	}
	public String getGiaBan(){
//	{
		return ttChiTiet.get(2);
	}	

	public String getHienTrang(){
//	{
		return ttChiTiet.get(3);
	}
	
	public String getThoiGianBaoHanh(){
//	{
		return ttChiTiet.get(4);
	}
	
	public String getThongTinKhuyenMai(){
//	{
		return ttChiTiet.get(5);
	}
	
	public String getMicroProcessor(){
//	{
		return ttChiTiet.get(6);
	}
	
	public String getCache(){
//	{
		return ttChiTiet.get(7);
	}
	public String getRam(){
//	{
		return ttChiTiet.get(8);
	}
	
	public String getVideoGraphic(){
//	{
		return ttChiTiet.get(9);
	}
	
	public String getHDD(){
//	{
		return ttChiTiet.get(10);
	}
	
	public String getMultimediaDrive(){
//	{
		return ttChiTiet.get(11);
	}
	
	public String getIntegrated(){
//	{
		return ttChiTiet.get(12);
	}
	
	public String getDisplay(){
//	{
		return ttChiTiet.get(13);
	}
	
	public String getNetWorkCard(){
//	{
		return ttChiTiet.get(14);
	}
	
	public String getWireless(){
//	{
		return ttChiTiet.get(15);
	}
	
	public String getKeyboard(){
//	{
		return ttChiTiet.get(16);
	}
	
	public String getPointing(){
//	{
		return ttChiTiet.get(17);
	}
	
	public String getExternalPort(){
//	{
		return ttChiTiet.get(18);
	}
		
	public String getWeight(){
//	{
		return ttChiTiet.get(19);
	}
		
	public String getSoft(){
//	{
		return ttChiTiet.get(20);
	}
	
	public String getHinhAnh(){
//	{
		return ttChiTiet.get(21);
	}
	
	public String getSoLuongTon(){
//	{
		return ttChiTiet.get(22);
	}
	
	public String getDongSanPham(){
//	{
		return ttChiTiet.get(23);
	}

	public boolean isOutPut(){
//	{
		if (i < spCungDongSanPham.size())
			return true;
		return false;
	}
	
}